package battleship;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


public class WelcomeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        HttpSession session = request.getSession();

        // if new session
//        if (!Context.sessions.contains(session)) {
//            System.out.println("new session!");
//            session.setAttribute("status", "login");
//            session.setAttribute("user", new User());
//            session.setAttribute("game", new Game());
//
//            // initialize queues of open and running games for this session
//            LinkedBlockingQueue<Game> openGamesQueue = new LinkedBlockingQueue<Game>();
//            session.setAttribute("openGamesQueue", openGamesQueue);
//
//            LinkedBlockingQueue<Game> runningGamesQueue = new LinkedBlockingQueue<Game>();
//            session.setAttribute("runningGamesQueue", runningGamesQueue);
//
//            LinkedBlockingQueue<Game> removeOpenGamesQueue = new LinkedBlockingQueue<Game>();
//            session.setAttribute("removeOpenGamesQueue", removeOpenGamesQueue);
//
//            LinkedBlockingQueue<Game> removeRunningGamesQueue = new LinkedBlockingQueue<Game>();
//            session.setAttribute("removeRunningGamesQueue", removeRunningGamesQueue);
//
//            Context.sessions.add(session);
//        }
        
        System.out.println("starting WelcomeServlet");
//        System.out.println("current status: " + session.getAttribute("status"));
//        System.out.println("session in Welcomeservlet: " + session + ", time: " + System.currentTimeMillis());

        RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp");
        rd.forward(request, response);
    }
}
